// src/api/customerService.js

import axios from "../utils/axios";

// 获取未读消息数
export const fetchUnreadMessageCount = async () => {
  try {
    const response = await axios.get('/customerService/unreadCount');
    return { data: response.data.unreadCount || 0 };
  } catch (error) {
    console.error('获取未读消息数失败:', error);
    return { data: 0 };
  }
};

// 获取客服消息列表
export const fetchCustomerServiceList = () => {
  return axios.get("/customerService/list");
};

// 获取特定会话的聊天历史
export const fetchChatHistory = (conversationId) => {
  return axios.get(`/customerService/chatHistory/${conversationId}`);
};

// 发送消息
export const sendMessage = (conversationId, content, receiver) => {
  return axios.post(`/customerService/sendMessage`, { conversationId, content, receiver });
};

// 标记消息为已读
export const markMessagesAsRead = (conversationId) => {
  return axios.put(`/customerService/markAsRead/${conversationId}`);
};

// 获取最近的会话列表
export const fetchRecentConversations = () => {
  return axios.get("/customerService/recentConversations");
};

// 关闭特定会话
export const closeConversation = (conversationId) => {
  return axios.put(`/customerService/closeConversation/${conversationId}`);
};